package org.sasha.roulette.dialog;


import java.util.Arrays;
import java.util.Collection;

import javax.inject.Inject;

import org.sasha.roulette.data.DBHelper;
import org.sasha.roulette.data.Spin;
import org.sasha.roulette.event.SpinRegisteredEvent;

import com.github.peholmst.mvp4vaadin.Presenter;
import com.google.common.eventbus.EventBus;
import com.vaadin.data.util.BeanItem;

@SuppressWarnings("serial")
public class SpinDialogPresenter extends Presenter<SpinDialogView> {
    
    private final DBHelper dbHelper;
    
    private final EventBus eventBus;
    
    @Inject
    public SpinDialogPresenter(final DBHelper dbHelper, final EventBus eventBus) {
        this.dbHelper = dbHelper;
        this.eventBus = eventBus;
    }
    
    public BeanItem<Spin> createSpinItem() {
        return new BeanItem<Spin>(new Spin());
    }
    
    public void saveSpin(final Spin spin) {
        dbHelper.saveSpin(spin);
        eventBus.post(new SpinRegisteredEvent(spin));
    }

    public Collection<?> getProperties() {
        return Arrays.asList(new Object[] {"color", "value", "timestamp"});
    }
}
